﻿//https://leetcode.cn/problems/length-of-last-word/

class Solution {
public:
    int lengthOfLastWord(string s)
    {
        int n = s.size();
        int count = 0;
        bool flag = false;
        for (int i = n - 1; i >= 0; i--)
        {
            if ((i == n - 1 && s[i] == ' ') || (flag && s[i] == ' '))
            {
                flag = true;
                continue;
            }
            if (s[i] == ' ')
            {
                break;
            }
            count++;
            flag = false;
        }

        return count;

    }
};
